/**
  ******************************************************************************
* @file				oled.h
* @Software			IAR 8.3 or MDK 5.28
* @Target 			CW32F030C8T6
* @author			何月明
* @date				2023-0617
  ******************************************************************************
  */

#ifndef __OLED_SIMIIC_H_
#define __OLED_SIMIIC_H_

#include "stdint.h"
#include "cw32f030.h"
#include "cw32f030_rcc.h"
#include "cw32f030_gpio.h"
#include "cw32f030_systick.h"
#include "oled_font.h"

////引脚配置
#define		OLED_SCL_PIN		GPIO_PIN_6
#define		OLED_SCL_PORT		CW_GPIOB
#define		OLED_SDA_PIN		GPIO_PIN_7
#define		OLED_SDA_PORT		CW_GPIOB	
////引脚电压设置

#define	delay_ms(ms) 		SysTickDelay(ms)
	
#define OLED_MODE 0
#define SIZE 8
#define XLevelL		0x00
#define XLevelH		0x10
#define Max_Column	128
#define Max_Row		64
#define	Brightness	0xFF 
#define X_WIDTH 	128
#define Y_WIDTH 	64	    						  
//-----------------OLED IIC端口定义----------------  					   
#define OLED_SCL_LOW() 		(OLED_SCL_PORT->BRR = OLED_SCL_PIN)//SCL
#define OLED_SCL_HIGH() 	(OLED_SCL_PORT->BSRR = OLED_SCL_PIN)
#define OLED_SDA_LOW() 		(OLED_SDA_PORT->BRR = OLED_SDA_PIN)//SDA
#define OLED_SDA_HIGH() 	(OLED_SDA_PORT->BSRR = OLED_SDA_PIN)
//-----------------OLED IIC端口定义---------------- 
#define OLED_CMD  0x00	//写命令
#define OLED_DATA 0x40	//写数据
//-----------------OLED 字库定义---------------- 
#define F8X16 		k_oled_8x16
#define F6X8		k_oled_6x8
#define FGB16 		k_oled_gb16
#define FGB24 		k_oled_gb24
//----------------OLED 字体大小------------------
#define SIZE_8X16 	16
#define SIZE_6X8	8
#define SIZE_GB16 	16
#define SIZE_GB24	24

//OLED控制用函数
void OLED_Init(void);
void OLED_SIMIIC_Init(void);

void OLED_IIC_Start(void);
void OLED_IIC_Stop(void);
void OLED_IIC_WaitAck(void);
void OLED_IIC_WriteByte(uint8_t IIC_Byte);
void OLED_IIC_WriteCommand(uint8_t IIC_Command);
void OLED_IIC_WriteData(uint8_t IIC_Data);
void OLED_WR_Byte(unsigned dat,unsigned cmd);  
void OLED_SetPos(uint8_t x, uint8_t y);
void OLED_Clear(void);
void OLED_DisplayOn(void);
void OLED_DisplayOff(void);	
void OLED_On(void);

//void OLED_DrawPoint(uint8_t x,uint8_t y,uint8_t t);
//void OLED_Fill(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint8_t dot);
void OLED_FillPicture(uint8_t fill_Data);
void OLED_ShowChar(uint8_t x,uint8_t y,const uint8_t chr,uint8_t size);
void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size);
void OLED_ShowString(uint8_t x,uint8_t y,const uint8_t *str,uint8_t size);	 
void OLED_DrawBMP(uint8_t x0, uint8_t y0,uint8_t x1, uint8_t y1,uint8_t BMP[]);
void OLED_ShowChinese(uint8_t x, uint8_t y, uint8_t *chin, uint8_t size);

void OLED_ShowGB16(uint8_t x, uint8_t y,uint8_t *chin);
void OLED_ShowGB24(uint8_t x, uint8_t y,uint8_t *chin);

#endif
